package com.zjxny.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import lombok.Getter;
import lombok.Setter;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.LinkTree;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.ChoiceType;
import xyz.erupt.annotation.sub_field.sub_edit.ReferenceTableType;
import xyz.erupt.annotation.sub_field.sub_edit.ReferenceTreeType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.upms.handler.DictCodeChoiceFetchHandler;
import xyz.erupt.upms.model.base.HyperModel;

@Setter
@Getter
@Entity
@Table(name = "sms_info")
@Erupt(
		name = "短信信息",linkTree = @LinkTree(field = "accountInfo")
		,power = @Power(add = false, delete = false, 
		edit = false, query = true, 
		importable = false, export = true)
)
public class SmsInfo extends HyperModel{

	private static final long serialVersionUID = 2653779833798950879L;
	
	@EruptField(
	        views =  @View(title = "所属公司", column = "simpleTitle"),
    		edit = @Edit(
    		            title = "所属公司"
    		            ,type = EditType.REFERENCE_TREE
    		            ,referenceTreeType = @ReferenceTreeType(pid = "parent.id",label = "simpleTitle")
    		)
	    )
	@ManyToOne
	AccountInfo accountInfo;
	
	@EruptField(
			views = {
			        @View(title = "模板编码", column = "code"),
			        @View(title = "模板名称", column = "title")
			},
    		edit = @Edit(
    		            title = "模板"
	            		,type = EditType.REFERENCE_TABLE
	                	,referenceTableType = @ReferenceTableType(id = "id", label = "title")
    		            ,search = @Search(vague = true)
    		)
	    )
	@ManyToOne
	SmsTplInfo smsTplInfo;
	
	@EruptField(
			views = {
			        @View(title = "姓名", column = "userName"),
			        @View(title = "手机号", column = "phoneNo")
			    },
    		edit = @Edit(
    		            title = "客户"
	            		,type = EditType.REFERENCE_TABLE,
	                	referenceTableType = @ReferenceTableType(id = "id", label = "userName")
    		            ,search = @Search(vague = true)
    		)
	    )
	@ManyToOne
	CustomerInfo customerInfo;
	
	@EruptField(
			views = @View(title = "号牌号码")
			,edit = @Edit(
					title="号牌号码"
					,type = EditType.INPUT
					,notNull = true
				)
	)
	@Column(name = "hphm", columnDefinition="varchar(10)")
	private String hphm;
	
	@EruptField(
			views = @View(title = "违章文书号")
			,edit = @Edit(
					title="违章文书号"
					,type = EditType.INPUT
					,notNull = true
				)
	)
	@Column(name = "xh", columnDefinition="char(16)")
	private String xh;
	
	@EruptField(
		views = {
				@View(title="违法时间", column = "wfsj"),
				@View(title="违法地址", column = "wfdz"),
		        @View(title = "记分值", column = "wfjfs"),
		        @View(title = "罚款金额", column = "fkje"),
		        @View(title="违法描述", column = "wfms"),
		    },
		edit = @Edit(
				title="违章详情"
				,type = EditType.REFERENCE_TABLE,
				referenceTableType = @ReferenceTableType(id = "id", label = "hphm")
			)
	)
	@OneToOne(cascade = CascadeType.ALL)
	private TrafficInfo trafficInfo;

//	@Column(name = "user_name", columnDefinition="varchar(30)")
//	private String userName;
//	
//	@Column(name = "phone_no", columnDefinition="varchar(15)")
//	private String phoneNo;
	
	@EruptField(
			views = @View(title = "短信内容")
			,edit = @Edit(
					title="短信内容"
					,type = EditType.TEXTAREA
					,notNull = true
				)
	)
	@Column(name = "content", columnDefinition="text")
	private String content;

	@EruptField(
			views = @View(title = "失败描述")
			, edit = @Edit(
				title = "失败描述"
			)
	)
	@Column(name = "error_msg", columnDefinition="text")
	private String errorMsg;

	@EruptField(
			views = @View(title = "短信类型")
			, edit = @Edit(
                    title = "短信类型"
                    ,search = @Search
                    ,type = EditType.CHOICE
        			,choiceType=@ChoiceType(fetchHandler = DictCodeChoiceFetchHandler.class,fetchHandlerParams = {"traffic_sms_type"} ) 
            )
	)
	private Integer type;
	
	@EruptField(
			views = @View(title = "短信状态")
			, edit = @Edit(
                    title = "短信状态"
                    ,search = @Search
                    ,type = EditType.CHOICE
        			,choiceType=@ChoiceType(fetchHandler = DictCodeChoiceFetchHandler.class,fetchHandlerParams = {"traffic_sms_status"} ) 
            )
	)
	private Integer status=0;

	@EruptField(
			views = @View(title = "最后发送日期")
			, edit = @Edit(
				title = "最后发送日期"
			)
	)
	@Column(name = "last_send_date", columnDefinition="date")
	private String lastSendDate;
	
	@EruptField(
			views = @View(title = "发送次数")
			, edit = @Edit(
			title = "发送次数"
			,search = @Search
	)
	)
	private Integer num=0;
}